using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Crossborder.Core.Core;
using Crossborder.Core.Enum;
using StackExchange.Redis;

namespace Crossborder.Common.RedisModule
{
    public interface IRedisWorker : ITransient
    {
        /// <summary>
        /// 删除Key
        /// </summary>
        /// <param name="key"></param>
        void RemoveKeys(string key);

        /// <summary>
        /// 删除Key（Async）
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task RemoveKeysAsync(string key);

        /// <summary>
        /// 查询 Redis string
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        string GetRedisString(string key);

        /// <summary>
        /// 查询 Redis string async
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<string> GetRedisStringAsync(string key);

        /// <summary>
        /// 写入Redis string 
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="value">value</param>
        /// <param name="ts">过期时间</param>
        /// <param name="spanEnum">时间类型（默认秒（Seconds））可选类型：秒（Seconds）,分钟（Minutes）,小时（Hours）,天（Day）</param>
        void SetRedisString(string key, string value, int ts, TimeSpanEnum spanEnum = TimeSpanEnum.Seconds);

        /// <summary>
        /// 写入Redis string（async）
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="value">value</param>
        /// <param name="ts">过期时间</param>
        /// <param name="spanEnum">时间类型（默认秒（Seconds））可选类型：秒（Seconds）,分钟（Minutes）,小时（Hours）,天（Day）</param>
        Task SetRedisStringAsync(string key, string value, int ts, TimeSpanEnum spanEnum = TimeSpanEnum.Seconds);

        /// <summary>
        /// 查询 Redis hash (async)
        /// </summary>
        /// <param name="key"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        Task<T> GetHashMemoryAsync<T>(string key) where T : new();

        /// <summary>
        /// 写入 Redis hash
        /// </summary>
        /// <param name="key"></param>
        /// <param name="values"></param>
        void SetHashMemory(string key, Dictionary<string, string> values);

        /// <summary>
        /// 写入 Redis hash
        /// </summary>
        /// <param name="key"></param>
        /// <param name="entries"></param>
        void SetHashMemory(string key, params HashEntry[] entries);

        /// <summary>
        /// 写入 Redis hash
        /// </summary>
        /// <param name="key"></param>
        /// <param name="entity"></param>
        /// <param name="type"></param>
        /// <typeparam name="T"></typeparam>
        void SetHashMemory<T>(string key, T entity, Type? type = null);

        /// <summary>
        /// 写入 Redis hash
        /// </summary>
        /// <param name="key"></param>
        /// <param name="entries"></param>
        /// <param name="func"></param>
        /// <typeparam name="T"></typeparam>
        void SetHashMemory<T>(string key, IEnumerable<T> entries, Func<T, IEnumerable<string>> func);

        // Task SetHashMemory<T>(string key, string cartId, T entity) where T : class;

        // Task GetHashAllMemory(string key);
    }
}